<!DOCTYPE html>
<html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>修改密码--layui后台管理模板 2.0</title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
    <link href="/resource/js/bstable/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="/resource/js/bstable/css/bootstrap-table.css" rel="stylesheet" type="text/css">
    <link href="/resource/css/table.css" rel="stylesheet" type="text/css">
</head>
<style>
</style>
<body style="background-color: #ecf0f5;font-family: 楷体;color: #475059;overflow: auto">
<div class="notice_main ">
    <div class="notice_check" style="padding: 16px 15px 8px 15px">
        <p>
            <label class="">商品编号：</label>
            <input type="text" id="productUuid" class="find_input">
            <label class="">商品名称：</label>
            <input type="text" id="productName" class="find_input">
            <button class="check_btn" id="search">查询</button>
        </p>
        <div class="clear"></div>
    </div>
    <table id="inventoryTables" lay-filter="inventoryTables"></table>
</div>
<script type="text/html" id="operate">
    <a class="toolbarMy" lay-event="del">删除</a>
</script>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript">
    var addInventory;
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            laydate = layui.laydate,
            form = layui.form;
        table.render({
            elem: '#inventoryTables'
            , url: '/inventory/outInventoryTable.do' //数据接口
            , method: 'get'
            , page: true //开启分页
            , id: 'tableId'
            , limits: [10, 15, 30]
            , limit: 15
            , cols: [
                [ //表头
                    {field: 'productUuid', title: '商品编号', 'fixed': 'left'}
                    , {field: 'productName', title: '名称'}
                    , {field: 'number', title: '数量'}
                    , {field: 'unitPrice', title: '单价'}
                    , {field: 'totalPrice', title: '合计'}
                    , {field: 'time', title: '出库时间'}
                    , {field: 'userName', title: '操作人'}
                    , {title: '操作', toolbar: '#operate', 'fixed': 'right'}
                ]
            ]
        });
        //搜索
        $('#search').on('click', function () {
            active.reload()
        });
        //监听工具条
        table.on('tool(inventoryTables)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'del') {
                //删除
                delInventory(data.id);
            }
        });

        //删除函数
        function delInventory(id) {
            layer.confirm('是否删除?', function (index) {
                $.ajax({
                    url: "/inventory/outInventory.do",
                    type: "post",
                    data: {_method: "DELETE", "id": id},
                    dataType: "json",
                    success: function (result) {
                        if (!result.status) {
                            layer.msg(result.msg, {time: 2000});
                            return false;
                        }
                        layer.msg("删除成功!", {time: 1000});
                        active.reload();
                    }
                });
                layer.close(index);
            })
        }

        active = {
            reload: function () {
                var productName = $("#productName").val();
                var productUuid = $("#productUuid").val()
                //执行重载
                table.reload('tableId', {
                    url: '/inventory/inventoryTable.do'
                    , method: 'get'
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        productName: productName,
                        productUuid: productUuid,
                    }
                });
            }
        };
    });
</script>

</body>
</html>